package com.qf.forumproject.service.impl;

import com.qf.forumproject.entity.QfCourseContent;
import com.qf.forumproject.dao.QfCourseContentDao;
import com.qf.forumproject.service.QfCourseContentService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import javax.annotation.Resource;
import java.util.List;


/**
 * (QfCourseContent表)服务实现类
 *
 * @author protagonist
 * @since 2022-07-23 11:43:01
 */
@Service("qfCourseContentServiceImpl")
public class QfCourseContentServiceImpl implements QfCourseContentService {
    @Resource
    private QfCourseContentDao qfCourseContentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public QfCourseContent selectById(Integer id) {
        return this.qfCourseContentDao.selectById(id);
    }

    /**
     * 分页查询
     *
     * @param current 当前页
     * @param size 每一页的条数
     * @return 对象列表
     */
    @Override
    public PageInfo<QfCourseContent> selectPage(int current, int size) {
        PageHelper.startPage(current,size);
        List<QfCourseContent> dataList = qfCourseContentDao.selectAll();
        return new PageInfo<>(dataList);
    }

    /**
     * 查询所有
     *
     * @return 实例对象的集合
     */
     @Override
     public List<QfCourseContent> selectAll() {
        return this.qfCourseContentDao.selectAll();
     }
     
    /**
     * 根据条件查询
     *
     * @return 实例对象的集合
     */
    @Override
    public List<QfCourseContent> selectList(QfCourseContent qfCourseContent) {
        return this.qfCourseContentDao.selectList(qfCourseContent);
    }
    
    /**
     * 新增数据
     *
     * @param qfCourseContent 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public int insert(QfCourseContent qfCourseContent) {
        return this.qfCourseContentDao.insert(qfCourseContent);
    }

    /**
     * 批量新增
     *
     * @param qfCourseContents 实例对象的集合
     * @return 生效的条数
     */
    @Override
    @Transactional
    public int batchInsert(List<QfCourseContent> qfCourseContents) {
        return this.qfCourseContentDao.batchInsert(qfCourseContents);
    }

    /**
     * 修改数据
     *
     * @param qfCourseContent 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public QfCourseContent update(QfCourseContent qfCourseContent) {
        this.qfCourseContentDao.update(qfCourseContent);
        return this.selectById(qfCourseContent.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    @Transactional
    public int deleteById(Integer id) {
        return this.qfCourseContentDao.deleteById(id);
    }
    
    /**
     * 查询总数据数
     *
     * @return 数据总数
     */
     @Override
     public int count(){
        return this.qfCourseContentDao.count();
     }
}
